#ifndef _USART1_H
#define _USART1_H

#include "sys_hc32f460.h"
#include <hc32f460_usart.h>

/* USART RX Port/Pin definition */
#define USART1_RX_PORT                   (PortC)
#define USART1_RX_PIN                    (Pin15)

/* USART TX Port/Pin definition */
#define USART1_TX_PORT                   (PortC)
#define USART1_TX_PIN                    (Pin13)

/* USART RX Port/Pin definition */
#define USART2_RX_PORT                   (PortA)
#define USART2_RX_PIN                    (Pin08)

/* USART TX Port/Pin definition */
#define USART2_TX_PORT                   (PortA)
#define USART2_TX_PIN                    (Pin10)

/* USART RX Port/Pin definition */
#define USART4_RX_PORT                   (PortB)
#define USART4_RX_PIN                    (Pin13)

/* USART TX Port/Pin definition */
#define USART4_TX_PORT                   (PortB)
#define USART4_TX_PIN                    (Pin15)

#define USART_RX_BUF_SIZE		2048

typedef struct{
	uint8_t 	timeout_flag;//串口连接超时标志
	uint32_t	timeout_cnt;//超时计数
	uint8_t 	recv_ok_flag;//串口接收完成标志
	uint16_t 	recv_len;//接收数据长度
	uint8_t 	recv_buf[USART_RX_BUF_SIZE];//接收缓冲区指针
}UsartRxInfo_t;

UsartRxInfo_t *get_uart1_info(void);
UsartRxInfo_t *get_uart2_info(void);
UsartRxInfo_t *get_uart4_info(void);

void usart1_init(uint32_t baud);
void usart2_init(uint32_t baud);
void usart1_send(uint8_t *buf,uint16_t len);
void usart2_send(uint8_t *buf,uint16_t len);
void usart1_sleep_enter(void);
void usart2_sleep_enter(void);

void usart4_init(uint32_t baud);
void usart4_send(uint8_t *buf,uint16_t len);
void usart4_sleep_enter(void);

void uart_printf(uint8_t comNum,char* fmt,...);

#endif
